package com.tsinghua.server.base.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tsinghua.server.common.Result;
import com.tsinghua.server.original.entity.FxjcCtz;
import com.tsinghua.server.original.entity.FxjcCyz;
import com.tsinghua.server.original.entity.FxjcJrz;
import com.tsinghua.server.original.service.FxjcCtzService;
import com.tsinghua.server.original.service.FxjcCyzService;
import com.tsinghua.server.original.service.FxjcJrzService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @description: 首页统计
 * @author: Mr.Eric
 * @create: 2022/3/5 15:24
 */
@RestController
@RequestMapping(value = "/index/")
public class IndexController {


    @Resource
    private FxjcCtzService ctzService;

    @Resource
    private FxjcCyzService cyzService;

    @Resource
    private FxjcJrzService jrzService;

    /**
     * 首页统计
     *
     * @return
     */
    @GetMapping(value = "data")
    public Result indexData() {

        // 城投债
        Integer ctzTotal = ctzService.count();
        Integer ctzWyTotal = 0;


        // 产业债
        Integer cyzTotal = cyzService.count();
        QueryWrapper<FxjcCyz> cyzWrapper = new QueryWrapper<>();
        cyzWrapper.eq("sfwy", 1);
        Integer cyzWyTotal = cyzService.count(cyzWrapper);


        // 金融债
        Integer jrzTotal = jrzService.count();
        QueryWrapper<FxjcJrz> jrzWrapper = new QueryWrapper<>();
        cyzWrapper.eq("sfwy", 1);
        Integer JrzWyTotal = 0; //jrzService.count(jrzWrapper);

        Map<String, Integer> params = new HashMap<>();

        //
        params.put("ctzTotal", ctzTotal);
        params.put("ctzWyTotal", ctzWyTotal);

        params.put("cyzTotal", cyzTotal);
        params.put("cyzWyTotal", cyzWyTotal);

        params.put("jrzTotal", jrzTotal);
        params.put("JrzWyTotal", JrzWyTotal);


        params.put("total", jrzTotal + cyzTotal + ctzTotal);
        params.put("wyTotal", JrzWyTotal + cyzWyTotal +ctzWyTotal );


        return Result.succ(params);

    }






}
